package com.xqgl.service;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.xqgl.bean.Admin;
import com.xqgl.dao.LoginDao;
import com.xqgl.util.ConnertionUtil;

public class LoginDaoImp implements LoginDao{
	Connection conn = ConnertionUtil.getConnection();
	PreparedStatement ps;
	Statement statement;
	
	@Override
	public Admin selectAdmin(String adminname) {
		Admin adm = new Admin();
		String sql = "select * from admin where adminname =?";
		try {
			ps = conn.prepareStatement(sql);
			ps.setString(1, adminname);
			ResultSet set = ps.executeQuery();
			while(set.next()){
				adm.setAdminname(set.getString("adminname"));
				adm.setAdminpassword(set.getString("adminpassword"));
				adm.setAdminphone(set.getInt("adminphone"));
				adm.setAdmincount(set.getInt("admincount"));
				adm.setAdminemail(set.getString("adminemail"));
				adm.setAdminpower(set.getString("adminpower"));
				adm.setAdminctime(set.getString("adminctime"));
			}
		} catch (SQLException e) {
			// TODO: handle exception
			e.printStackTrace();
		} finally{
			try {
				ps.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return adm;
	}
	
//	@Override
//	public int add(Admin admin) throws SQLException {
//		Admin adm = new Admin();
//		String sql = "insert into admin(adminname,adminpassword,adminphone,adminemail,adminpower,adminctime,adminstate)values(?,?,?,?,?,?,?)";
//		ps = conn.prepareStatement(sql);
//		ps.setString(1, adm.getAdminname());
//		ps.setString(2, adm.getAdminpassword());
//		ps.setInt(3, adm.getAdminphone());
//		ps.setString(4, adm.getAdminemail());
//		ps.setString(5, adm.getAdminpower());
//		ps.setString(6, adm.getAdminctime());
//		ps.setString(7, adm.getAdminstate());
//		int a = ps.executeUpdate();
//		ps.close();
//		return a;
//	}
	
	@Override
	public int update(int admincount,String adminname) throws SQLException {
		String sql ="update admin set admincount = "+admincount+" where adminname='"+adminname+"'";
		ps = conn.prepareStatement(sql);
		int b = ps.executeUpdate();
		ps.close();
		return b;
	}
	
//	@Override
//	public int delete(Admin admin) throws SQLException {
//		Admin adm = new Admin();
//		String sql="delete from admin where adminname ='" + adm.getAdminname() +"'";
//		ps = conn.prepareStatement();
//		int c = ps.executeUpdate(sql);
//		ps.close();
//		return c;
//	}


}
